<template>
  <div>
    <h3>总库存维护</h3>
        <hr>
        <div style="display: flex;margin-left: 500px">
<!--          <el-button type="primary" @click="BatchStore">批次库存</el-button>-->
          <el-button type="primary" @click="BuyPlan">采购计划</el-button>
          <el-button type="primary" @click="ProviderOrder">供应商发货单</el-button>
          <el-button type="primary" @click="GoodsInDetail">入库明细</el-button>
          <el-button type="primary" @click="GoodsOutDetail">出库上架明细</el-button>
        </div>

    <hr>
    <el-table
        :data="tableData.slice((currentPage-1)*PageSize,currentPage*PageSize)" style="width: 100%">
      <!--1.-->
      <el-table-column
          prop="code"
          label="商品编号"
      >
      </el-table-column>
      <!--2.-->
      <el-table-column
          prop="goodsName"
          label="商品名称"
      >
      </el-table-column>
      <!--3.-->
      <el-table-column
          prop="stockNum"
          label="库存总量">
      </el-table-column>
      <!--4.-->
      <el-table-column
          prop="scope"
          label="阈值">
      </el-table-column>
      <!--5.-->
      <el-table-column
          prop="type"
          label="商品类型">
      </el-table-column>
      <!--6.-->
      <el-table-column
          prop="specs"
          label="商品规格">
      </el-table-column>
      <!--7.-->
      <el-table-column
          prop="sellPrice"
          label="售价">
      </el-table-column>
      <!--8.-->
      <el-table-column
          prop="aveInPrice"
          label="最新采购价">
      </el-table-column>
      <!--8.-->
      <el-table-column
          prop="state"
          label="状态">
      </el-table-column>
      <!--9.-->
      <el-table-column
          label="操作"
      >
        <template slot-scope="scope">
          <!--          <el-button type="text" size="small" @click="del(scope.row.userId)" >删除</el-button>-->
          <el-button type="text" size="small" @click="UpdateScope(scope.row)"><i class="el-icon-edit"></i>修改阈值</el-button>

        </template>
      </el-table-column>


    </el-table>

    <!--页面选择导航--开始-->
    <div class="tabListPage">
      <el-pagination @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="currentPage"
                     :page-sizes="pageSizes"
                     :page-size="PageSize" layout="total, sizes, prev, pager, next, jumper"
                     :total="totalCount">
      </el-pagination>
    </div>
    <!--页面选择导航--结束-->

  </div>
</template>

<script>
export default {

  //一、名称区
  name: "ShoppingStorage",
  //二、数据区
  data(){
    return{
      //1.分页表格数据--开始//
      tableData:[],
      totalCount:null,


      currentPage:1,
      pageSizes:[1,2,3,4],
      PageSize:3,
      //分页表格数据--结束//
      input:'',

    }
  },
  //三、方法区
  methods:{
    init(){

      this.$axios.get("/sscsys/sysgoods2/findAll").then(
          r=>{

            this.tableData=r.data;
            this.totalCount=r.data.length;

          });
    },
    //1.分页表格换页方法--开始//
    handleSizeChange(val) {
      this.PageSize=val
      this.currentPage=1
    },
    handleCurrentChange(val) {
      this.currentPage=val
    },
//1.分页表格换页方法--结束//
//     BatchStore(){
//       this.$router.push("BatchStore")
//     },

    GoodsInDetail(){
      this.$router.push("GoodsInDetail")
    },
    GoodsOutDetail(){
      this.$router.push("GoodsOutDetail")
    },
    ProviderOrder(){
      this.$router.push("ProviderOrder")
    },
    BuyPlan(){
      this.$router.push("BuyPlan")
    },
//修改阈值
    UpdateScope(row){
      let that=this
      this.$prompt('请输入新的阈值', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',

      }).then(({ value }) => {

        that.$axios.put("sscsys/buyplan/updateScope/"+row.id+"/"+value).then(
            r=>{
             if(r.data=="ok"){
               this.$message.success("修改成功")
               this.init();
             }else{
               this.$message.success("修改失败")
             }
            }
        )
      }).catch(() => {
        this.$message.info("取消修改")
      });
    }

  },
  //四、初始化区
  mounted() {
    this.init();
  }

}
</script>



<style scoped>

</style>